package com.tao.myanr

import android.os.Bundle
import android.os.Handler
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.tao.anr.ANRDog
import com.tao.anr.ANRListener
import com.tao.anr.AnrInfo


class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
//        val anrWatchDog = ANRWatchDog()
//        // anr监听
//        anrWatchDog.setANRListener {  
//            it.printStackTrace()
//            
//        }
//        anrWatchDog.start()
//        //anr拦截器
//        anrWatchDog.setANRInterceptor {  }
//        //anr拦截监听
//        anrWatchDog.setInterruptionListener {  }
//        // 是否忽略调试断点
//        anrWatchDog.setIgnoreDebugger()
//        //是否报告所有线程
//        anrWatchDog.setLogThreadsWithoutStackTrace()
//        //设置匹配所有线程
//        anrWatchDog.setReportAllThreads()
//        // 设置匹配指定线程名称
//        anrWatchDog.setReportThreadNamePrefix()
//        // 设置只报告主线程
//        anrWatchDog.setReportMainThreadOnly()
        
        ANRDog.Build().apply {
            
            anrListener = object : ANRListener {
                override fun onAnr(anrInfo: AnrInfo) {
                    Log.e(" main " , " onAnr " +anrInfo.error?.message)
                    anrInfo.error?.printStackTrace()
                }
            }
        }.build().start()
        
        testCrash()
   
    }

    private fun testCrash() {

        Handler().postDelayed({
            Thread.sleep(7000)
            testCrash()
        },1000)
    }
}